import wx from './wx'
import Fly from 'flyio/dist/npm/wx'

const request = new Fly()
request.config.headers = {
  'content-type': 'application/x-www-form-urlencoded'
}

request.config.timeout = 10 * 1000
request.interceptors.request.use((request) => {
  wx.showLoading({ title: '拼命加载中...' })
  return request
})

request.interceptors.response.use(
  (response, promise) => {
    wx.hideLoading()
    return promise.resolve(response.data)
  },
  (err, promise) => {
    wx.hideLoading()
    wx.showToast({
      title: err.message,
      icon: 'none'
    })
    return promise.resolve()
  }
)

export default request
